
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeUnit;

import static junit.framework.TestCase.fail;
import static org.hamcrest.CoreMatchers.*;

import org.junit.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

public class EteamsRegister {
	private WebDriver driver;
	private String baseUrl;
	private boolean acceptNextAlert = true;
	private StringBuffer verificationErrors = new StringBuffer();

	@Before
	public void setUp() throws Exception {
		String value = "D:\\geckodriver-v0.16.1-win64\\geckodriver.exe";   //驱动浏览器jar包//在webapp/lib目录下
		String key="webdriver.gecko.driver";
		System.setProperty(key, value);
		driver = new FirefoxDriver();
		baseUrl = "https://castest.teems.cn/";
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}

	@org.junit.Test
	public void testEteamsregister() throws Exception {
		driver.get(baseUrl + "/login?service=http%3A%2F%2Fding.teems.cn");

		driver.findElement(By.id("account")).click();
		driver.findElement(By.id("account")).clear();
		driver.findElement(By.id("account")).sendKeys("18516500192");
		driver.findElement(By.id("account")).clear();
		driver.findElement(By.id("account")).sendKeys("18516500192");
		driver.findElement(By.id("username")).clear();
		driver.findElement(By.id("username")).sendKeys("guo");
		driver.findElement(By.id("username")).clear();
		driver.findElement(By.id("username")).sendKeys("guo");
		driver.findElement(By.id("password")).clear();
		driver.findElement(By.id("password")).sendKeys("123456");
		driver.findElement(By.id("password")).clear();
		driver.findElement(By.id("password")).sendKeys("123456");
		driver.findElement(By.id("password2")).clear();
		driver.findElement(By.id("password2")).sendKeys("123456");
		driver.findElement(By.id("password2")).clear();
		driver.findElement(By.id("password2")).sendKeys("123456");
		driver.findElement(By.id("user-submit-btn")).click();
		driver.findElement(By.id("user-submit-btn")).click();
		driver.findElement(By.id("not-validated-mobile")).click();
		driver.findElement(By.id("not-validated-mobile")).click();
		driver.findElement(By.id("create-btn")).click();
		driver.findElement(By.id("tenantName")).clear();
		driver.findElement(By.id("tenantName")).sendKeys("零一九二");
		driver.findElement(By.id("tenantName")).clear();
		driver.findElement(By.id("tenantName")).sendKeys("零一九二");
		driver.findElement(By.id("finish-btn")).click();
		driver.findElement(By.id("finish-btn")).click();
		driver.findElement(By.linkText("不提示")).click();
		driver.findElement(By.linkText("不提示")).click();
		driver.findElement(By.id("invite-m-cancel")).click();
		driver.findElement(By.id("invite-m-cancel")).click();
	}

	@After
	public void tearDown() throws Exception {
		driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}

	private boolean isAlertPresent() {
		try {
			driver.switchTo().alert();
			return true;
		} catch (NoAlertPresentException e) {
			return false;
		}
	}

	private String closeAlertAndGetItsText() {
		try {
			Alert alert = driver.switchTo().alert();
			String alertText = alert.getText();
			if (acceptNextAlert) {
				alert.accept();
			} else {
				alert.dismiss();
			}
			return alertText;
		} finally {
			acceptNextAlert = true;
		}
	}
}
